package com.house.auth.controller;

import java.util.Arrays;
import java.util.Map;

import com.house.common.to.UserTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.house.auth.entity.PowerEntity;
import com.house.auth.service.PowerService;
import com.house.common.utils.PageUtils;
import com.house.common.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author yangxinyu
 * @email yangxinyu03201@gmail.com
 * @date 2022-04-22 13:40:34
 */
@RestController
@RequestMapping("auth/power")
public class PowerController {
    @Autowired
    private PowerService powerService;

    /**
     * 构建 token
     */
    @PostMapping("/createToken")
    public R createToken(@RequestBody UserTo user){
        return  powerService.createToken(user);
    }

    /**
     * 解析token
     */
    @RequestMapping("/getId")
    public R getId(HttpServletRequest request){
        return powerService.getId(request);
    }
    /**
     * 其他微服务通过token获取用户id
     */
    @RequestMapping("/feignGetId")
    public R feignGetId(@RequestParam String token){
        return powerService.feignGetId(token);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = powerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{pid}")
    public R info(@PathVariable("pid") Integer pid){
		PowerEntity power = powerService.getById(pid);

        return R.ok().put("power", power);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PowerEntity power){
		powerService.save(power);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PowerEntity power){
		powerService.updateById(power);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] pids){
		powerService.removeByIds(Arrays.asList(pids));

        return R.ok();
    }

}
